﻿using Abp.Application.Services.Dto;
using shenghua.Basics.ShippingTemplates;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shenghua.Basics.ShippingTemplateSetting.Dto
{
    public class ShippingTemplateDto: EntityDto
    {
        public string Name { get; set; }
        public string DisplayName { get; set; }
        public bool Enabled { get; set; }
        public ShippingTemplateType TemplateType { get; set; }
        public double Freight { get; set; }
        public int FirstNumber { get; set; }
        public int AddedNumber { get; set; }
        public double AddedFreight { get; set; }
        public List<string> Areas { get; set; }
        public bool AllowFreeShipping { get; set; }
        public List<FreeShippingConditionDto> FreeShippingConditions { get; set; }


        public ShippingTemplateDto(ShippingTemplate shippingTemplate)
        {
            Id = shippingTemplate.Id;
            Name = shippingTemplate.Name;
            DisplayName = shippingTemplate.DisplayName;
            Enabled = shippingTemplate.Enabled;
            TemplateType = shippingTemplate.TemplateType;
            Freight = shippingTemplate.Freight;
            FirstNumber = shippingTemplate.FirstNumber;
            AddedNumber = shippingTemplate.AddedNumber;
            AddedFreight = shippingTemplate.AddedFreight;
            Areas = shippingTemplate.Areas.Items;
            AllowFreeShipping = shippingTemplate.AllowFreeShipping;

            FreeShippingConditions = new List<FreeShippingConditionDto>();
            foreach(var item in shippingTemplate.FreeShippingConditions)
            {
                FreeShippingConditions.Add(new FreeShippingConditionDto
                {
                    Areas = item.Areas,
                    MinCount = item.MinCount,
                    MinAmount = item.MinAmount
                });
            }
        }
    }

    public class FreeShippingConditionDto
    {
        public List<string> Areas { get; set; }
        public int MinCount { get; set; }
        public double MinAmount { get; set; }
    }
}
